package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;


    @Override
    public PageResult<Student> page(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());//开启分页，会改变SQL语句，紧跟的查询语句会进行分页处理，SQL语句末尾加上limit ?,?

        List<Student> studentList =studentMapper.list();//empList是list集合,list是page的父类，list->page要强转;查询的是全部数据
        //根据
        Page<Student> p = (Page<Student>) studentList;//获取总条数和数据


        return new PageResult<Student>(p.getTotal(),p.getResult());//返回总条数和数据
    }

    @Override
    public void delete(List<Integer> id) {
        studentMapper.deleteByIds(id);
    }

    @Override
    public void save(Student student) {

        studentMapper.insert(student);//执行完之后，emp对象中id属性值被赋值
    }

    @Override
    public Student getInfo(Integer id) {
        return studentMapper.getById(id);
    }

    @Override
    public void update(Student student) {
        studentMapper.updateById(student);
    }

    @Override
    public void updateViolation(Integer id, Integer score) {
        studentMapper.updateViolation(id,score);
    }
}
